include Enumerable
class AgentInterface
  def initialize(agent, files)
    @files = files
    @agent = agent
  end

  def publish_to_server
    server = @agent.server_interface
    @files.each{ |file| server.publish(file, @agent.host) }
  end

  def find_file(path)
    #TODO should be private
    @files.find { |file| file.path == path }
  end

  def update_file(path, content)
    file = find_file(path)
    raise "#{path} does not exist on #{@agent.host}" if file.nil?
    file.content = content
  end

  def execute_file(path)
    file = find_file(path)
    raise "#{path} does not exist on #{@agent.host}" if file.nil?
    file.execute
  end
end
